/**
 * @format
 * @Author: TC
 * @Date: 2021-09-27 18:10:15
 * @Last Modified by: TC
 * @Last Modified time: 2023-10-23 20:20:34
 */

import { _decorator, approx, Camera, EventHandler, Layout, Material, Node, Toggle } from "cc";
import { app } from "../../FrameWork/App";
import { BaseScene } from "../../FrameWork/Module/Component/BaseScene";
import { PostEffectBase } from "../../FrameWork/Module/PostEffect/PostEffectBase";
import { PostEffectGrap } from "../../FrameWork/Module/PostEffect/PostEffectGrap";
import { PostEffectGray } from "../../FrameWork/Module/PostEffect/PostEffectGray";
import { PostEffectResult } from "../../FrameWork/Module/PostEffect/PostEffectResult";
import { ASSERT_TYPE } from "../../FrameWork/Module/Res/ResConst";
import { nsExtend } from "../../FrameWork/Util/ExtendUtil";
import { nsBundleConst } from "../Const/BundleConst";
const { ccclass, property } = _decorator;

@ccclass("PostEffectScene")
export class PostEffectScene extends BaseScene {
    @property(Node)
    nodeLayout: Node = null;

    private _peNameList: string[] = [];

    onLoad() {
        super.onLoad();
        this.nodeLayout.active = false;
        app.loaderMgr.loadDir(nsBundleConst.Shader, "2D", () => {
            this.nodeLayout.active = true;
        });
    }

    protected addEvent(): void {
        super.addEvent();
    }

    onDestroy() {
        super.onDestroy();
    }

    onToggle(t: Toggle): void {
        let pe = app.postEffectMgr;
        if (t.isChecked) {
            nsExtend.pushToArr(t.node.name, this._peNameList);
        } else {
            nsExtend.removeFromArr(t.node.name, this._peNameList);
        }

        if (this._peNameList.length > 0) {
            pe.peList = [];
            pe.peList.push(new PostEffectGrap());
            let cls: PostEffectBase = null;
            this._peNameList.forEach((name) => {
                switch (name) {
                    case "置灰":
                        cls = new PostEffectGray();
                        break;
                }
                pe.peList.push(cls);
            });
            pe.peList.push(new PostEffectResult());
            pe.open();
        } else {
            pe.close();
        }
    }
}
